<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/user_php.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
	$con = @mysql_connect('localhost', 'root', '');
	if (!$con) {
		die("Đã xảy ra lỗi trong quá trình xử lý." . mysql_error());
	}
	
	$db_selected = @mysql_select_db('studial');
	if (!$db_selected) {
		die("Đã xảy ra lỗi trong quá trình xử lý." . mysql_error());
	}

	$sql="SELECT * FROM friends WHERE (user_id='".$_COOKIE['studialuserid']."' AND friend_id='".$_GET['id']."') OR (friend_id='".$_COOKIE['studialuserid']."' AND user_id='".$_GET['id']."');";
	$result = mysql_query($sql);
	$rows = mysql_num_rows($result);
	$i = 2; //themselves
	if($rows)
	{
		//friend
		$i = 1;
	}
	else if ($_COOKIE['studialuserid'] != $_GET['id'])
	{
		//not friend
		$i = 0;
	}
	
	//Get homeboard info
	$sql="SELECT * FROM `users` WHERE `id`='".$_GET['id']."'";
	$result=mysql_query($sql);
	$row=mysql_fetch_array($result);
	$fullnametarget=$row["lastname"]." ".$row["firstname"];
	
	//Get homeboard info
	$sql="SELECT * FROM `users` WHERE `id`='".$_COOKIE['studialuserid']."'";
	$result=mysql_query($sql);
	$row=mysql_fetch_array($result);
	$fullnameuser=$row["lastname"]." ".$row["firstname"];
?>
<title><?php echo $fullnametarget; ?></title>
<link rel="stylesheet" type="text/css" href="../css/global.css" />
<link rel="stylesheet" type="text/css" href="../css/loggedpages.css" />
<!-- InstanceBeginEditable name="head" -->
<style type="text/css">
	#coursetable {
		width: 560px;
		margin: 2em 0 2em 2em;
		border-width: 0;
	}
	
	#coursetable td {
		width: inherit;
		border-top: 1pt solid #d0d0d0;
		padding: 20px 10px 20px 10px;
		font-size: 13px;
	}
	
	td#headrow {
		border-top-width: 0;
		padding: 0 0 10px 0;	
	}
	
	.greenbutton { 
		width: auto; 
		margin-top: 0;
	}
	
	.courseinfo {
		float: left;
		width: 410px;	
	}
	
	.coursename {
		font-size: 14px;
		font-weight: 700;
		margin-bottom: 0.3em;	
	}
	
	.coursedesc { color: #888888; }
	
	.courseact {
		float: right;
		text-align: right;
		width: 120px;	
	}
</style>
<!-- InstanceEndEditable -->
</head>

<body>  
    <div class="header">
        <div class="innercontent">
            <img alt="Studial" class="logo" src="../images/logo.jpg" />   
            <form id="searchform" method="post" action="">
                <div id="searchblock">
                    <input id="searchfield" name="searchfield" type="text" placeholder="Tìm kiếm" />
                    <button id="searchbutton" type="submit" name="search" value="1" title="Tìm kiếm" onclick="window.location = '../unlogged/index.php'"><img id="searchicon" src="../images/searchicon.png" /></button>
                </div>           
            </form>
            <div id="rightheader">
                <a class="headerbutton" id="logout" href="../unlogged/logout.php"><span id="borderleft"></span>Đăng xuất</a>
                <a class="headerbutton" id="toboard" href="<?php echo "../users/addfriend.php?id=".$_COOKIE["studialuserid"]; ?>"><?php echo $fullnameuser; ?></a>
            </div>
        </div>
    </div>
    <div class="innercontent">
        <div id="leftcolumn">
            <img alt="Avatar" id="largeavatar" src="<?php echo $path = "../images/male_avatar.png"; ?>" />
        	<div id="sidenavcontainer">	
                <ul id="sidenav">
            		<li><a class="navlink" href="homeboard.php?id=<?php echo $_GET['id']; ?>"><span id="boardnav">Bảng</span></a></li>
                    <li><a class="navlink" href="infoview.php?id=<?php echo $_GET['id']; ?>"><span id="infonav">Thông tin</span></a></li>
                    <li><a class="navlink" href="friendlist.php?id=<?php echo $_GET['id']; ?>"><span id="friendnav">Bạn bè</span></a></li>
                    <li><a class="navlink" href="phovidallview.php?id=<?php echo $_GET['id']; ?>"><span id="phovidnav">Phim ảnh</span></a></li>
                    <li><a class="navlink" href="courselist.php?id=<?php echo $_GET['id']; ?>"><span id="coursenav">Khóa học</span></a></li>
            	</ul>
            </div>
        </div>
        <div id="contentcolumn">
        	<div id="contentcolheader">
            	<h2><?php echo $fullnametarget; ?></h2>
                <?php 
					if ($i == 0) { 
						echo "<a id=\"addfriend\" href=\"../users/addfriend.php?id=".$_GET["id"]."\"><button class=\"greenbutton\">Kết bạn</button></a>";
					}
				 	else if ($i == 1) {
						echo "<a id=\"removefriend\" href=\"../users/removefriend.php?id=".$_GET["id"]."\"><button class=\"greenbutton\">Chia tay</button></a>"; 
					}
				?>  
            </div>
		<!-- InstanceBeginEditable name="maincontent" -->
          	<table id="coursetable">
                <tr>
                    <td id="headrow"><a href=""><button class="greenbutton">Tạo khóa học</button></a></td>
                </tr>
                <?php
					$id = $_GET['id'];
					$result1 = mysql_query("SELECT * FROM `courses` WHERE `administrator_id` = '".$id."';");
					$num1 = mysql_num_rows($result1);
					if ($num1 > 0)
					{
						for($u = 0 ; $u < $num1 ; $u++)
						{
							$rows = mysql_fetch_array($result1);
							echo "<tr>";
							echo "<td>";
							echo "<div class=\"courseinfo\"";
							if ($i != 2)
								echo " style=\"width: inherit;\"";
							echo ">";
							echo "<div class=\"coursename\"><a href=\"../courses/homeboard.php?id=".$rows['id']."\">".$rows['name']."</a></div>";	
							echo " <div class=\"coursedesc\">".$rows['description']."</div>";
							echo "<div class=\"coursedesc\">Tham gia với vai trò <strong>Giảng viên</strong></div>";
							echo "</div>";
							if($i == 2)
								echo "<div class=\"courseact\"><a href=\"../courses/removecourse.php?id=".$rows['id']."\">Xóa khóa học</a></div>";
							echo "</td>";
							echo "</tr>";
						}
					}
					
					
					$result2 = mysql_query("SELECT * FROM `enroll` INNER JOIN `courses` ON `enroll`.`course_id` = `courses`.`id` WHERE `enroll`.`user_id` = '".$id."';");
					$num2 = mysql_num_rows($result2);
					if ($num2 > 0)
					{
						for($u = 0 ; $u < $num2 ; $u++)
						{
							$rows = mysql_fetch_array($result2);
							echo "<tr>";
							echo "<td>";
							echo "<div class=\"courseinfo\"";
							if ($i != 2)
								echo " style=\"width: inherit;\"";
							echo ">";
							echo "<div class=\"coursename\"><a href=\"../courses/homeboard.php?id=".$rows['course_id']."\">".$rows['name']."</a></div>";	
							echo " <div class=\"coursedesc\">".$rows['description']."</div>";
							echo "<div class=\"coursedesc\">Tham gia với vai trò <strong>";
							if($rows['role'] == 1)
								echo "Trợ giảng</strong></div>";
							else
								echo "Sinh viên</strong></div>";
							echo "</div>";
							if($i == 2)
								echo "<div class=\"courseact\"><a href=\"../courses/leavecourse.php?id=".$rows['id']."\">Bỏ khóa học</a></div>";	
							echo "</td>";
							echo "</tr>";
						}
					}
				?>
            </table>
		<!-- InstanceEndEditable -->
    	</div>
    </div>
    <div class="footer">
    	<div id="leftfooter">Studial @ 2012 - Nhóm 01</div>
        <div id="rightfooter">
			<a href="" title="Đăng ký thêm tên trường vào hệ thống">Đăng ký trường</a>
            -
            <a href="" title="Đăng ký thêm tên ngành học vào hệ thống">Đăng ký ngành</a>
        </div>
    </div>       
</body>
<!-- InstanceEnd --></html>
